import Toast from 'tdesign-miniprogram/toast';
import {
  getNoticeById
} from '../../services/notice/index';

Page({
  data: {
    banner: '',
    time: 0,
    showBannerDesc: false,
    statusTag: '',
    detail: {}
  },

  onLoad(query) {
    const id = parseInt(query.noticeId);
    this.getNoticeList(id);
  },

  getNoticeList(id) {
    getNoticeById(id).then((res) => {
      if (res.data.code == 200) {
        const obj = res.data.data
        if (obj.noticeContent) {
          obj.noticeContent = obj.noticeContent.replace(/<img/gi, '<img style="max-width:100%;height:auto;margin:0 auto;display:block"')
        }
        this.setData({
          detail: obj
        })
      }
    });
  },

  goodClickHandle(e) {
    const {
      index
    } = e.detail;
    const {
      spuId
    } = this.data.list[index];
    wx.navigateTo({
      url: `/pages/goods/details/index?spuId=${spuId}`
    });
  },

  cardClickHandle() {
    Toast({
      context: this,
      selector: '#t-toast',
      message: '点击加购',
    });
  },

  bannerClickHandle() {
    Toast({
      context: this,
      selector: '#t-toast',
      message: '点击规则详情',
    });
  },
});